<template></template>

<script>
import axios from "axios";
import Qs from 'qs'
import Cookies from "js-cookie";
import { encrypt, decrypt } from "@/utils/jsencrypt";

export default {
  name: "Login",
  data() {
    return {};
  },
  watch: {
    $route: {
      handler: function (route) {
        console.log(route);
        this.redirect = route.query && route.query.redirect;
      },
      immediate: true,
    },
  },
  created() {
    //获取后台参数
    this.decipherToken();
  },
  methods: {
    decipherToken() {
      const portalUrl = this.portalUrl;
      let rParam = {
        "token" : this.$route.query.token
      };
      const $this = this;

      axios({
        method: 'post',
        url: portalUrl + "/sso/webapp/decipherToken",
        data: Qs.stringify(rParam),
        headers: { 'Content-type': 'application/x-www-form-urlencoded;charset=utf-8'}
      }).then(res=>{
          if(res.status==200 && res.data && res.data.code===0){
            console.log("认证成功！！！");
            $this.ssoLogin(res.data.data.uid);
          }else{
            $this.$router.push('/401');
          }
          
        
      }).catch(function (error) {
          console.log(error);
          $this.$router.push('/401');
        });
    },
    ssoLogin(jobNo){
       var userinfo = {
        userName: ''
      }
      sessionStorage.setItem('userinfo', JSON.stringify(userinfo))
      this.$store
          .dispatch('PortalSsoLogin', jobNo)
          .then(() => {
            this.$router.push({ path: '/' })
          })
          .catch(() => {
          })
    }
  },
};
</script>

